package com.its.common.net.client.handler;

import cn.hutool.extra.spring.SpringUtil;
import com.its.common.net.core.BaseNetHandlerExecutor;
import com.its.common.net.core.dto.GenericNetDTO;
import com.its.common.net.core.handler.BaseGenericHandler;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author xiaxp
 * @Date 9/14/22 13:02
 * @Description
 */
@Slf4j
public class ClientHandlerExecutor extends BaseNetHandlerExecutor<Boolean> {
    private ClientHandlerExecutor(){}

    public static ClientHandlerExecutor getInstance(){
        return SpringUtil.getBean(ClientHandlerExecutor.class);
    }


    @Override
    protected Boolean doExec(Object... reqs) {
        try {
            BaseGenericHandler handler = (BaseGenericHandler) reqs[0];
            ChannelHandlerContext ctx = (ChannelHandlerContext) reqs[1];
            GenericNetDTO data = (GenericNetDTO) reqs[2];
            handler.handleData(ctx, data);
        }catch (Exception e){
            log.error(e.toString());
        }
        return Boolean.TRUE;
    }
}
